<template>
  <div class="student">
    <h2>学生姓名：{{ name }}</h2>
    <h2>学生性别：{{ sex }}</h2>
  </div>
</template>

<script>

import pubsub from 'pubsub-js'

export default {
  name: "Student",
  data() {
    return {
      name: '张三',
      sex: '男'
    }
  },
  methods:{
    receiveSchoolName(schoolName){
      console.log('Student组件接收到了SchoolName：',schoolName)
    }
  },
  mounted() {
    this.pubId=pubsub.subscribe('hello',function (msg){
      console.log('有人发布了hello消息：',msg)
    })
  },
  beforeDestroy() {
    pubsub.unsubscribe(this.pubId)
  }


}
</script>

<style scoped>
.student {
  background-color: skyblue;
  padding: 5px;
  margin-top: 30px;
}
</style>